using System;

namespace ICommonLibrary.Date {

    /// <summary>
    /// This class is yet to complete. Its design concept is the same as MutableDate, 
    /// more method will be added on demand.
    /// </summary>
    public sealed class MutableTime : IComparable {

        /// <summary>
        /// Returns a value between 0 and 23
        /// </summary>
        public int Hour {
            get { return _hour; }
        }

        /// <summary>
        /// Returns a value between 0 and 59
        /// </summary>
        public int Minute {
            get { return _minute; }
        }

        /// <summary>
        /// Returns a value between 0 and 59
        /// </summary>
        public int Second {
            get { return _second; }
        }
        
        private int _hour;
        private int _minute;
        private int _second;
        private int _uniqueKey;

        public MutableTime(int hour, int minute, int second) {
            _hour = hour % 24;
            _minute = minute % 60;
            _second = second % 60;
            _uniqueKey = GenerateUniqueKey(_hour, _minute, _second);
        }

        private MutableTime(int hour, int minute, int second, int uniqueKey) {
            _hour = hour;
            _minute = minute;
            _second = second;
            _uniqueKey = uniqueKey;
        }

        public MutableTime Clone() {
            return new MutableTime(_hour, _minute, _second, _uniqueKey);
        }

        public int CompareTo(object o) {
            if (o == null) {
                return 1;
            }
            if (o == this) {
                return 0;
            }
            var d = o as MutableTime;
            if (d == null) {
                return 1;
            }
            return _uniqueKey - d._uniqueKey;
        }

        public int GetHour() {
            return _hour;
        }

        public int GetMinute() {
            return _minute;
        }

        public int GetSecond() {
            return _second;
        }

        private static int GenerateUniqueKey(int h, int m, int s) {
            return h * 10000 + m * 100 + s;
        }
    }
}